package Acwing;

import java.util.Scanner;

public class Demo95 {
    public static int N=10;
    static int n=0;
    static int[] path=new int[N];
    static int[] ifUse=new int[N];
    public static void Acw(int u){
        //递归结束，直接打印
        if(u>n){
            for (int i = 1; i <= n; i++) {
                System.out.print(path[i]+" ");
            }
            System.out.println();
            return;
        }
        for(int i=1;i<=n;i++) {
            if (ifUse[i] == 0) {
                path[u] = i;
                ifUse[i] = 1;
                Acw(u + 1);
                ifUse[i] = 0;
            }
        }
    }
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        n=s.nextInt();
        Acw(1);

    }
}
